<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>新增宠物</title>
<script type="text/javascript" src="js/jquery-1.12.4.js"></script>
<script type="text/javascript">
	function resst() {
		var name = $("#name").val();
		var breed = $("#breed").val();
		var sex = $("#sex").val();
		var birthday = $("#birthday").val();
		var description = $("#description").val();
		if (name == "") {
			alert("昵称不能为空！");
			return false;
		}
		if (birthday == ""
				|| !(isNaN(birthday) && !isNaN(Date.parse(birthday)))) {
			alert("日期格式不正确");
			return false;
		}
		return true;
	}

	function unied() {
		var name = $("#name").val();
		$.getJSON("PetUnied", "name=" + name, function(data) {
			if (data > 0) {
				alert("昵称已存在");
				return false;
			} else {
				alert("昵称可以使用");
				return true;
			}
		});
	}
</script>
</head>
<body>
	<form action="AddServlet" method="post" onsubmit="return resst()">
		昵称: <input type="text" name="name" id="name" onblur="return unied()"><br>
		<br> 品种: <select name="breed" id="breed">
			<option value="0">--请选择--</option>
			<option value="1">狗</option>
			<option value="2">猫</option>
			<option value="3">鸟</option>
			<option value="4">兔</option>
		</select><br>
		<br> 性别: <input type="radio" value="1" name="sex" id="sex"
			checked="checked">雄 &nbsp; &nbsp; &nbsp; <input type="radio"
			value="2" name="sex" id="sex">雌<br>
		<br> 出生日期: <input type="text" name="birthday" id="birthday"><br>
		<br> 宠物描述:
		<textarea name="description" id="description"></textarea>
		<br>
		<br> <input type="submit" value="提交"> <input
			type="reset" value="重置">
	</form>
</body>
</html>